package com.lhx.wechat.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.alibaba.fastjson.JSON;
import com.lhx.wechat.entity.menu.Menu;

/**
 * 创建菜单
 */
public class WechatCreateMenuUtil {

	private static final Logger logger = LoggerFactory.getLogger(WechatCreateMenuUtil.class);
	// 菜单创建（POST） 限100（次/天）
	private static String menu_create_url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=%s";

	public static void createMenu(Menu menu, String appId) {
		String token = WechatAccessTokenUtil.getToken(appId);
		String url = String.format(menu_create_url, token);
		try {
			CustomerSimpleHttpClient simpleHttpClient = new CustomerSimpleHttpClient();
			String body = simpleHttpClient.post(url, JSON.toJSONString(menu));
			logger.info("create menu:" + body);

		} catch (Exception e) {
			logger.error(e.getMessage());
		}
	}

}
